<template>
    <div>
        <!-- 搜索组件 -->
        <search-form :items="formItems" :params="params" :on-submit="onSearch" :btn-loading="loading" />

        <!-- 表格区域 -->
        <div class="table-body">
            <!-- 左上角按钮 -->
            <div class="table-right-top"></div>

            <!-- 表格 -->
            <el-table border style="width: 100%;" :data="data" v-loading="loading">
                <el-table-column align="center" prop="date" :label="$i18n.t('DATE')" :min-width="120" fixed="left"></el-table-column>
                <el-table-column align="center" prop="repayment_num" :label="$i18n.t('REPAYMENT_NUM')" :min-width="120"></el-table-column>
                <el-table-column align="center" prop="can_double_loan_num" :label="$i18n.t('CAN_DOUBLELOAN_NUM')" :min-width="120"></el-table-column>
                <el-table-column align="center" :label="$i18n.t('DAY1_DOUBLELOAN_APPLY')" :min-width="120">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" :content="$i18n.t('NUM') + ': ' + scope.row.day1_loan_apply_num" placement="right">
                            <span>{{ scope.row.day1_loan_apply_rate }}</span>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column align="center" :label="$i18n.t('DAY3_DOUBLELOAN_APPLY')" :min-width="120">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" :content="$i18n.t('NUM') + ': ' + scope.row.day3_loan_apply_num" placement="right">
                            <span>{{ scope.row.day3_loan_apply_rate }}</span>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column align="center" :label="$i18n.t('DAY7_DOUBLELOAN_APPLY')" :min-width="120">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" :content="$i18n.t('NUM') + ': ' + scope.row.day7_loan_apply_num" placement="right">
                            <span>{{ scope.row.day7_loan_apply_rate }}</span>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column align="center" :label="$i18n.t('DOUBLELOAN_APPLY')" :min-width="120">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" :content="$i18n.t('NUM') + ': ' + scope.row.loan_apply_num" placement="right">
                            <span>{{ scope.row.loan_apply_rate }}</span>
                        </el-tooltip>
                    </template>
                </el-table-column>

                <el-table-column align="center" :label="$i18n.t('DAY1_DOUBLELOAN_SUCCESS')" :min-width="120">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" :content="$i18n.t('NUM') + ': ' + scope.row.day1_loan_success_num" placement="right">
                            <span>{{ scope.row.day1_loan_success_rate }}</span>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column align="center" :label="$i18n.t('DAY3_DOUBLELOAN_SUCCESS')" :min-width="120">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" :content="$i18n.t('NUM') + ': ' + scope.row.day3_loan_success_num" placement="right">
                            <span>{{ scope.row.day3_loan_success_rate }}</span>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column align="center" :label="$i18n.t('DAY7_DOUBLELOAN_SUCCESS')" :min-width="120">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" :content="$i18n.t('NUM') + ': ' + scope.row.day7_loan_success_num" placement="right">
                            <span>{{ scope.row.day7_loan_success_rate }}</span>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column align="center" :label="$i18n.t('DOUBLELOAN_SUCCESS')" :min-width="120" fixed="right">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" :content="$i18n.t('NUM') + ': ' + scope.row.loan_success_num" placement="right">
                            <span>{{ scope.row.loan_success_rate }}</span>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>

            <!-- 分页 -->
            <div class="table-pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next, ->, sizes"
                    :page-size.sync="page.perPage"
                    :total="page.total"
                    :page-count="page.pageCount"
                    :current-page.sync="page.currentPage"
                    :page-sizes="PAGES_SIZE"
                    @current-change="onCurrentPageChange"
                    @size-change="onPerPageChange"
                >
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
    import SearchForm from '@/components/SearchForm'
    import { getDoubleloanPerformance } from '@/api/report'
    import { PAGES_SIZE } from '@/config/constants'

    export default {
        name: 'doubleloanPerformance',
        components: { SearchForm },
        data () {
            return {
                PAGES_SIZE,
                params: {
                    loan_number: [null, null]
                },
                data: [],
                page: {
                    total: 0,
                    currentPage: 1,
                    perPage: PAGES_SIZE[0],
                    pageCount: 1
                },
                loading: false,
                drawer: false,
                mdl: {},
                all: {}
            }
        },
        created () {
            this.fetch()
        },
        computed: {
            formItems () {
                // 构建搜索表单
                return [
                    { title: this.$i18n.t('REPAYMENT_TIME'), type: 'date-range', key: 'date' },
                    { title: this.$i18n.t('LOAN_NUMBER'), type: 'input-number-range', key: 'loan_number' }
                ]
            }
        },
        methods: {
            // 搜索按钮
            onSearch () {
                this.fetch()
            },
            // 从接口拉取数据
            fetch () {
                this.loading = true
                getDoubleloanPerformance({ ...this.params, page: this.page.currentPage, perPage: this.page.perPage }).then((res) => {
                    // eslint-disable-next-line camelcase
                    const { data, last_page, total, all } = res.result
                    this.data = data
                    this.all = all
                    this.page.total = total
                    // eslint-disable-next-line camelcase
                    this.page.pageCount = last_page
                }).finally(() => {
                    this.loading = false
                })
            },
            // 页数切换
            onCurrentPageChange (page) {
                this.page.currentPage = page
                this.fetch()
            },
            // 每页显示数量修改
            onPerPageChange (perPage) {
                this.page.perPage = perPage
                this.fetch()
            },
            // 统计数据
            getSummaries () {
                return [
                    this.$i18n.t('TOTAL'),
                    this.all.due_num,
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    '',
                    this.all.no_repayment_num,
                    this.all.no_repayment_rate
                ]
            }
        }
    }
</script>

<style lang="less" scoped>
</style>
